package com.gnerv.sylvanas.business.manage.storage;

import com.gnerv.sylvanas.business.manage.model.dto.ViewDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ViewTreeDTO;
import com.gnerv.sylvanas.business.manage.model.entity.View;
import com.gnerv.sylvanas.business.manage.repository.mapper.RoleViewMapper;
import com.gnerv.sylvanas.business.manage.repository.mapper.ViewMapper;
import com.gnerv.sylvanas.business.manage.repository.mapper.ViewRouteMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class ViewStorageService {

    private final ViewMapper viewMapper;
    private final RoleViewMapper roleViewMapper;
    private final ViewRouteMapper viewRouteMapper;

    
    public int insert(View view) {
        return viewMapper.insert(view);
    }

    
    public int deleteByUkId(String ukId) {
        return viewMapper.deleteByUkId(ukId);
    }

    
    public int updateByUkId(View view) {
        return viewMapper.updateByUkId(view);
    }

    
    public ViewDTO selectByUkId(String ukId) {
        return viewMapper.selectByUkId(ukId);
    }

    
    public List<ViewDTO> selectListByName(String name) {
        return viewMapper.selectListByName(name);
    }

    
    public List<ViewDTO> selectListByParentUkId(String parentUkId) {
        return viewMapper.selectListByParentUkId(parentUkId);
    }

    
    public List<ViewTreeDTO> selectListTreeByParentUkId(String parentUkId) {
        return viewMapper.selectListTreeByParentUkId(parentUkId);
    }

    
    public List<ViewTreeDTO> selectListTreeByParentUkIdAndAccountUkId(String parentUkId, String accountUkId) {
        return viewMapper.selectListTreeByParentUkIdAndAccountUkId(parentUkId, accountUkId);
    }

    
    public int bindRole(String viewUkId, Set<String> roleUkIdList, String creator) {
        return roleViewMapper.insertRoleView(viewUkId, roleUkIdList, creator);
    }

    
    public int unbindRole(String viewUkId) {
        return roleViewMapper.deleteByViewUkId(viewUkId);
    }

    
    public int bindRoute(String viewUkId, String routeUkId, String creator) {
        return viewRouteMapper.insertViewRoute(viewUkId, routeUkId, creator);
    }

    
    public int unbindRoute(String viewUkId) {
        return viewRouteMapper.deleteByViewUkId(viewUkId);
    }
}
